package com.spicesoft.clientobjects.samples.checkbox;

import java.awt.FlowLayout;

import javax.swing.*;

import com.jgoodies.binding.adapter.BasicComponentFactory;
import com.jgoodies.binding.beans.PropertyAdapter;
import com.spicesoft.clientobjects.BeanEnhancer;
import com.spicesoft.clientobjects.BeanRegistry;

/**
 * This examples shows how two GUI elements can be bound to a POJO object
 * that does not support property change listeners.
 * 
 * @author Yegor Jbanov
 */
public class CheckBoxSample {

  public static void main(String[] args) {
    BeanRegistry.registerType(MyPOJO.class);
    
    MyPOJO pojo = new MyPOJO();
    MyPOJO bean = BeanEnhancer.addPropertyChangeSupport(pojo);

    PropertyAdapter adapter = new PropertyAdapter(bean, "booleanValue", true);
    JCheckBox box1 = BasicComponentFactory.createCheckBox(adapter, "Boolean Value 1");
    JCheckBox box2 = BasicComponentFactory.createCheckBox(adapter, "Boolean Value 2");

    JFrame frame = new JFrame();
    frame.getContentPane().setLayout(new FlowLayout());
    frame.getContentPane().add(box1);
    frame.getContentPane().add(box2);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }

}
